﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace DapperDal.DapperBase
{
    public interface IBaseBll<TPrimay, TEntity> where TEntity : class, new()
    {
        /// <summary>
        /// 新增一条数
        /// </summary>
        /// <param name="entity"></param>
        /// <returns></returns>
        TPrimay Insert(TEntity entity);

        /// <summary>
        /// 批量添加数据
        /// </summary>
        /// <param name="list"></param>
        void Insert(IEnumerable<TEntity> list);

        /// <summary>
        /// 根据主键获取实体
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        TEntity GetSingle(TPrimay id);

        /// <summary>
        /// 逻辑删除(软删除)
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        bool SoftDelete(TPrimay id);

        /// <summary>
        /// 修改数据
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        bool Update(TEntity entity);
    }

    public class BaseBll<TPrimay, TEntity> : IBaseBll<TPrimay, TEntity> where TEntity : class, new()
    {

        public IDapperBaseDAL<TPrimay, TEntity> _baseDal;

        /// <summary>
        /// 根据主键获取实体
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        public TEntity GetSingle(TPrimay id)
        {
            return _baseDal.GetSingle(id);
        }

        /// <summary>
        /// 批量添加数据
        /// </summary>
        /// <param name="list"></param>
        public void Insert(IEnumerable<TEntity> list)
        {
            _baseDal.Insert(list);
        }

        /// <summary>
        /// 新增一条数
        /// </summary>
        /// <param name="entity"></param>
        /// <returns></returns>
        public TPrimay Insert(TEntity entity)
        {
            return _baseDal.Insert(entity);
        }

        /// <summary>
        /// 逻辑删除(软删除)
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        public bool SoftDelete(TPrimay id)
        {
            return _baseDal.SoftDelete(id);
        }

        /// <summary>
        /// 更新数据
        /// </summary>
        /// <param name="entity"></param>
        /// <returns></returns>
        public bool Update(TEntity entity)
        {
            return _baseDal.Update(entity);
        }
    }
}

